package org.lili.lambdaexp;

import org.lili.semanticmodel.Edge;
import org.lili.semanticmodel.Graph;

import java.util.function.Consumer;

/**
 * @author lili
 * @description ${DESCRIPTION}
 * @create 2018-04-22 下午3:51
 * @since
 **/
public class GraphBuilder {

    Graph graph;

    public GraphBuilder() {
        graph = new Graph();
    }

    public static Graph Graph(Consumer<GraphBuilder> gConsumer) {
        GraphBuilder gBuilder = new GraphBuilder();
        gConsumer.accept(gBuilder);
        return gBuilder.graph;
    }

    public void edge(Consumer<EdgeBuilder> eConsumer){
        EdgeBuilder eBuilder = new EdgeBuilder();
        eConsumer.accept(eBuilder);
        Edge e = eBuilder.edge();
        graph.addEdge(e);
        graph.addVertice(e.getFromVertex());
        graph.addVertice(e.getToVertex());
    }
}
